package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.CourseDesign;
import com.ruoyi.teaching.service.ICourseDesignService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 课程设计Controller
 *
 * @author sunshine
 * @date 2024-01-26
 */
@RestController
@RequestMapping("/course_design")
public class CourseDesignController extends BaseController
{
    @Autowired
    private ICourseDesignService courseDesignService;

    /**
     * 查询课程设计列表
     */
    @RequiresPermissions("teaching:course_design:list")
    @GetMapping("/list")
    public TableDataInfo list(CourseDesign courseDesign)
    {
        startPage();
        List<CourseDesign> list = courseDesignService.selectCourseDesignList(courseDesign);
        return getDataTable(list);
    }

    /**
     * 导出课程设计列表
     */
    @RequiresPermissions("teaching:course_design:export")
    @Log(title = "课程设计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseDesign courseDesign)
    {
        List<CourseDesign> list = courseDesignService.selectCourseDesignList(courseDesign);
        ExcelUtil<CourseDesign> util = new ExcelUtil<CourseDesign>(CourseDesign.class);
        util.exportExcel(response, list, "课程设计数据");
    }

    /**
     * 获取课程设计详细信息
     */
    @RequiresPermissions("teaching:course_design:query")
    @GetMapping(value = "/{stageId}")
    public TableDataInfo getInfo(@PathVariable("stageId") Long stageId)
    {
        List<CourseDesign> list = courseDesignService.selectCourseDesignById(stageId);
        return getDataTable(list);
    }

    /**
     * 新增课程设计
     */
    @RequiresPermissions("teaching:course_design:add")
    @Log(title = "课程设计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseDesign courseDesign)
    {
        return toAjax(courseDesignService.insertCourseDesign(courseDesign));
    }

    /**
     * 修改课程设计
     */
    @RequiresPermissions("teaching:course_design:edit")
    @Log(title = "课程设计", businessType = BusinessType.UPDATE)
    @PutMapping("/{stage}")
    public AjaxResult editAndInsert(@RequestBody List<CourseDesign> courseDesign)
    {

        return AjaxResult.success(courseDesignService.updateCourseDesign(courseDesign));
    }
    @RequiresPermissions("teaching:course_design:edit")
    @Log(title = "课程设计", businessType = BusinessType.UPDATE)
    @PutMapping("/relatedInterview/{cdId}")
    public AjaxResult relatedInterview(@PathVariable("cdId") Long cdId,@RequestBody List<Long> interviewIdList)
    {

        return AjaxResult.success(courseDesignService.updateRelatedInterview(cdId,interviewIdList));
    }


}
